package com.hrhx.duhongming.fel;

import org.apache.commons.math3.util.FastMath;
import org.junit.Test;

import com.greenpineyu.fel.FelEngine;
import com.greenpineyu.fel.FelEngineImpl;
import com.greenpineyu.fel.context.FelContext;

public class FelCore {
	
	private static FelEngine fel = new FelEngineImpl(); 
	private static FelContext ctx = fel.getContext();
	
	public static Double[][] getResult(String expression, Double[] data){
		Double resultData[][] = new Double[data.length][2];
        for(int i=0;i<data.length;i++){
        	ctx.set("x", data[i]);
        	Object evalDouble = fel.eval(expression,ctx);    
        	resultData[i][0]=data[i];
        	resultData[i][1]=Double.parseDouble(evalDouble.toString());
		}
        return resultData;
	}
	
	@Test
	public void test(){
  
//		ctx.set("out", System.out);   
//		ctx.set("FEL",new FelCore() ); 
//		fel.eval("out.println('Hello Everybody'.substring(6)+$('FastMath').pow(10.0,4))");
		
		FelEngine fel = new FelEngineImpl();   
		FelContext ctx = fel.getContext(); 
		Double d =FastMath.pow(10, 4);
		Object dd = fel.eval("$('org.apache.commons.math3.util.FastMath').pow(10.0,4)");
		System.out.println(dd);
	}
}
